package com.atguigu.rabbitmq.producer.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitmqDirectExchangeConfiguration {

    // 声明交换机
    @Bean
    public Exchange directExchange() {
        return ExchangeBuilder.directExchange("direct_exchange").durable(true).build();
    }

    // 声明队列
    @Bean
    public Queue directQueue01() {
        return QueueBuilder.durable("direct_queue_01").build();
    }

    // 声明队列
    @Bean
    public Queue directQueue02() {
        return QueueBuilder.durable("direct_queue_02").build();
    }

    // 声明队列和交换机的绑定信息 后面在给交换机direct_exchange发消息相当于也给direct_queue_01 类型为error发消息
    @Bean
    public Binding directQueue01Binding() {
        return BindingBuilder.bind(directQueue01()).to(directExchange())
                .with("error").noargs();
    }

    // 声明队列和交换机的绑定信息 后面在给交换机direct_exchange发消息相当于也给direct_queue_02 类型为error发消息
    @Bean
    public Binding bindingQueue02BindingErrorRoutingKey() {
        return BindingBuilder.bind(directQueue02()).to(directExchange())
                .with("error").noargs();
    }

    // 声明队列和交换机的绑定信息 后面在给交换机direct_exchange发消息相当于也给direct_queue_02 类型为info发消息
    @Bean
    public Binding bindingQueue02BindingInfoRoutingKey() {
        return BindingBuilder.bind(directQueue02()).to(directExchange())
                .with("info").noargs();
    }

    // 不管给交换机direct_exchange发 info 还是error ，direct_queue_02队列都会接收到消息

}